﻿using Ibp.Service.Entity.ODAEntity;
using OdaOperation.Model;

namespace OdaOperation.Client
{
    /// <summary>
    /// 生成Dwg文件
    /// </summary>
    public class GenDwg
    {
        /// <summary>
        /// 生成DWG
        /// </summary>
        /// <returns></returns>
        public string GenerateDWG()
        {
            string dwgpath = $@"D:\WebServer\FileServer\Empty.dwg";
            if (!File.Exists(dwgpath))
            {
                return null;
            }
            string tempFolder = @"D:\Dwg";
            if (!Directory.Exists(tempFolder))
            {
                Directory.CreateDirectory(tempFolder);
            }

            FileInfo fileInfo = new FileInfo(dwgpath);
            var filename = fileInfo.Name;
            var newfilename = Path.Combine(@"D:\Dwg", $"{Guid.NewGuid().ToString("N")}.dwg");
            fileInfo.CopyTo(newfilename, true);

            DbOperation dbOperation = new DbOperation();
            try
            {
                //开始调用ODA对文件进行处理
                dbOperation.InitOda();
                var db = dbOperation.ReadFile(newfilename);  //拷贝dwg文件路径
                ///线
                ///  public static void AppendOdDbMLeader(this DbDatabase db, LeaderModel leader, Action<OdDbMLeader> action = null)
                var leader = new LeaderModel()
                {
                    LayerName = "我不知",
                    FirstVertex = new DPoint(1, 0, 0),
                    LeaderLine = new DPoint(100, 100, 0),
                    TextContent = "文本内容",
                    TextHeight = 300,
                    ArrowSymbolName="111"
                };
                //db.AppendOdDbMLeader(leader);


                db.Commit(newfilename);
                dbOperation.UnInitOda();

                return newfilename;
            }
            catch (Exception ex)
            {
                dbOperation.UnInitOda();
                return null;
            }
        }

    }
}
